package user

import (
	"github.com/bgmp/config"
	"github.com/bgmp/handler"
	"github.com/bgmp/model"
	"github.com/gin-gonic/gin"
)

func (b Base) HasUser(c *gin.Context, req *HasUserRequest) *HasUserResponse {
	u := &model.User{Username: req.Username}
	if err := u.GetByName(config.DB); err != nil {
		handler.Errorf(c, err.Error())
		return nil
	}
	return &HasUserResponse{
		HasUser: u.ID != 0,
	}
}

type HasUserRequest struct {
	Username string `json:"username"`
}

type HasUserResponse struct {
	HasUser bool `json:"has_user"`
}
